/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.webhomesites.locacao.view;

import br.com.webhomesites.configuracao.utils.ConfiguracaoInstancias;
import br.com.webhomesites.locacao.contracts.IManutencaoView;
import br.com.webhomesites.locacao.model.EmpresaManutencaoModel;
import br.com.webhomesites.locacao.model.ItensManutencaoTableModel;
import br.com.webhomesites.locacao.model.ManutencaoTableModel;
import br.com.webhomesites.padrao.model.ProdutoModel;
import br.com.webhomesites.padrao.utils.DigitosPermitidos;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.*;
import java.util.List;
import javax.swing.JTextField;
import javax.swing.table.TableColumnModel;
import javax.swing.text.Document;

/**
 *
 * @author Webhome
 */
public class ManutView extends javax.swing.JInternalFrame implements IManutencaoView, FocusListener {

    /**
     * Creates new form ManutencaoView
     */
    public ManutView() {
        initComponents();

        txtManutencaoDataPrevManutencao.setDocument(new DigitosPermitidos());
        comboManutencaoDescricaoProduto.removeAllItems();
        comboManutencaoNomeCliente.removeAllItems();
        txtManutencaoCodigoManutencao.setHorizontalAlignment(JTextField.RIGHT);
        txtManutencaoCodigoProduto.setHorizontalAlignment(JTextField.RIGHT);
        txtManutencaoSerieProduto.setHorizontalAlignment(JTextField.RIGHT);
        txtManutencaoValorTotal.setHorizontalAlignment(JTextField.RIGHT);
        txtManutencaoValorTotal.setEditable(false);
        txtManutencaoSerieProduto.setEditable(false);
        
        txtManutencaoCodigoManutencao.addFocusListener(this);
        txtManutencaoCodigoProduto.addFocusListener(this);       
        txtManutencaoDataPrevManutencao.addFocusListener(this);
        
        //txtManutencaoValorTotal = new JMoneyField();

        //txtManutencaoValorItem.setDocument(new MaskMoedaDocument());

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelManutencao = new javax.swing.JPanel();
        btnCancelarManutencao = new javax.swing.JButton();
        txtManutencaoCodigoManutencao = new javax.swing.JTextField();
        labelManutencaoCodigo = new javax.swing.JLabel();
        comboManutencaoNomeCliente = new javax.swing.JComboBox();
        labelManutencaoNomeCliente = new javax.swing.JLabel();
        labelManutencaoDataManutencao = new javax.swing.JLabel();
        labelManutencaoDataPrevManutencao = new javax.swing.JLabel();
        txtManutencaoDataPrevManutencao = new javax.swing.JTextField();
        btnSalvarManutencao = new javax.swing.JButton();
        txtManutencaoDataManutencao = new javax.swing.JTextField();
        btnNovoManutencao = new javax.swing.JButton();
        txtManutencaoValorTotal = new javax.swing.JTextField();
        labelManutencaoValorTotal = new javax.swing.JLabel();
        btnPesquisarManutencao = new javax.swing.JButton();
        painelIncluirProduto = new javax.swing.JPanel();
        txtManutencaoCodigoProduto = new javax.swing.JTextField();
        labelManutencaoSerieProduto = new javax.swing.JLabel();
        txtManutencaoSerieProduto = new javax.swing.JTextField();
        labelManutencaoCodProduto = new javax.swing.JLabel();
        comboManutencaoDescricaoProduto = new javax.swing.JComboBox();
        labelManutencaoDescricaoProduto = new javax.swing.JLabel();
        btnNovoItem = new javax.swing.JButton();
        btnSalvarItem = new javax.swing.JButton();
        btnCancelarItem = new javax.swing.JButton();
        btnRemoverItem = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaManutencaoProblemaProduto = new javax.swing.JTextArea();
        labelManutencaoProblemaProduto = new javax.swing.JLabel();
        btnEmitirContrato = new javax.swing.JButton();
        btnAprovarManutencao = new javax.swing.JButton();
        scrollTabelaItens = new javax.swing.JScrollPane();
        tabelaManutencaoItensManutencao = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabelaManutencao = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);

        painelManutencao.setBorder(javax.swing.BorderFactory.createTitledBorder("Manutenção"));

        btnCancelarManutencao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/block-icon.png"))); // NOI18N
        btnCancelarManutencao.setMnemonic('c');

        labelManutencaoCodigo.setText("Cód.Manut");

        comboManutencaoNomeCliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione o nome" }));

        labelManutencaoNomeCliente.setText("Nome Empresa Manutenção");

        labelManutencaoDataManutencao.setText("Data Saída");

        labelManutencaoDataPrevManutencao.setText("Data Prev. Dev.");

        btnSalvarManutencao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/save-icon.png"))); // NOI18N
        btnSalvarManutencao.setMnemonic('s');

        btnNovoManutencao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/document-icon.png"))); // NOI18N
        btnNovoManutencao.setMnemonic('n');

        txtManutencaoValorTotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtManutencaoValorTotal.setForeground(new java.awt.Color(0, 0, 153));

        labelManutencaoValorTotal.setText("Valor Total");

        btnPesquisarManutencao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/search-icon.png"))); // NOI18N
        btnPesquisarManutencao.setMnemonic('p');

        javax.swing.GroupLayout painelManutencaoLayout = new javax.swing.GroupLayout(painelManutencao);
        painelManutencao.setLayout(painelManutencaoLayout);
        painelManutencaoLayout.setHorizontalGroup(
            painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelManutencaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelManutencaoLayout.createSequentialGroup()
                        .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labelManutencaoCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                            .addComponent(txtManutencaoCodigoManutencao))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(comboManutencaoNomeCliente, 0, 322, Short.MAX_VALUE)
                            .addGroup(painelManutencaoLayout.createSequentialGroup()
                                .addComponent(labelManutencaoNomeCliente)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelManutencaoLayout.createSequentialGroup()
                        .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtManutencaoDataManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelManutencaoDataManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelManutencaoDataPrevManutencao)
                            .addComponent(txtManutencaoDataPrevManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtManutencaoValorTotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelManutencaoValorTotal, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelManutencaoLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnNovoManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnSalvarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(9, 9, 9)
                        .addComponent(btnPesquisarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        painelManutencaoLayout.setVerticalGroup(
            painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelManutencaoLayout.createSequentialGroup()
                .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelManutencaoCodigo)
                    .addComponent(labelManutencaoNomeCliente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(comboManutencaoNomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtManutencaoCodigoManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(painelManutencaoLayout.createSequentialGroup()
                            .addComponent(labelManutencaoDataManutencao)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtManutencaoDataManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtManutencaoDataPrevManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(painelManutencaoLayout.createSequentialGroup()
                            .addComponent(labelManutencaoDataPrevManutencao)
                            .addGap(26, 26, 26)))
                    .addGroup(painelManutencaoLayout.createSequentialGroup()
                        .addComponent(labelManutencaoValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtManutencaoValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(painelManutencaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnCancelarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSalvarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnNovoManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPesquisarManutencao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        painelIncluirProduto.setBorder(javax.swing.BorderFactory.createTitledBorder("Incluir Produto"));

        labelManutencaoSerieProduto.setText("Série Produto");

        labelManutencaoCodProduto.setText("Cód. Prod.");

        comboManutencaoDescricaoProduto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione o produto" }));
        comboManutencaoDescricaoProduto.setActionCommand("S");

        labelManutencaoDescricaoProduto.setText("Descrição Produto");

        btnNovoItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/document-icon.png"))); // NOI18N
        btnNovoItem.setMnemonic('n');

        btnSalvarItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/save-icon.png"))); // NOI18N
        btnSalvarItem.setMnemonic('s');

        btnCancelarItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/block-icon.png"))); // NOI18N
        btnCancelarItem.setMnemonic('c');

        btnRemoverItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/delete-icon.png"))); // NOI18N
        btnRemoverItem.setMnemonic('x');

        txaManutencaoProblemaProduto.setColumns(20);
        txaManutencaoProblemaProduto.setRows(5);
        jScrollPane1.setViewportView(txaManutencaoProblemaProduto);

        labelManutencaoProblemaProduto.setText("Problema");

        javax.swing.GroupLayout painelIncluirProdutoLayout = new javax.swing.GroupLayout(painelIncluirProduto);
        painelIncluirProduto.setLayout(painelIncluirProdutoLayout);
        painelIncluirProdutoLayout.setHorizontalGroup(
            painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelIncluirProdutoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelIncluirProdutoLayout.createSequentialGroup()
                        .addGroup(painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(painelIncluirProdutoLayout.createSequentialGroup()
                                .addGroup(painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(labelManutencaoCodProduto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(txtManutencaoCodigoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(comboManutencaoDescricaoProduto, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labelManutencaoDescricaoProduto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(painelIncluirProdutoLayout.createSequentialGroup()
                                .addGroup(painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelManutencaoSerieProduto)
                                    .addComponent(txtManutencaoSerieProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane1))
                        .addGap(14, 14, 14))
                    .addGroup(painelIncluirProdutoLayout.createSequentialGroup()
                        .addComponent(btnNovoItem, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnSalvarItem, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnRemoverItem, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelarItem, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(painelIncluirProdutoLayout.createSequentialGroup()
                        .addComponent(labelManutencaoProblemaProduto)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        painelIncluirProdutoLayout.setVerticalGroup(
            painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelIncluirProdutoLayout.createSequentialGroup()
                .addGroup(painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelManutencaoCodProduto)
                    .addComponent(labelManutencaoDescricaoProduto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtManutencaoCodigoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboManutencaoDescricaoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelManutencaoSerieProduto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtManutencaoSerieProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelManutencaoProblemaProduto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painelIncluirProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnNovoItem, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSalvarItem, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelarItem, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRemoverItem, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnEmitirContrato.setText("Devolver");
        btnEmitirContrato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEmitirContratoActionPerformed(evt);
            }
        });

        btnAprovarManutencao.setText("Recibo");

        tabelaManutencaoItensManutencao.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        scrollTabelaItens.setViewportView(tabelaManutencaoItensManutencao);

        tabelaManutencao.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tabelaManutencao);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(painelManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(btnEmitirContrato, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(btnAprovarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(scrollTabelaItens, javax.swing.GroupLayout.DEFAULT_SIZE, 523, Short.MAX_VALUE)
                    .addComponent(painelIncluirProduto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(painelManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnEmitirContrato, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnAprovarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(painelIncluirProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(scrollTabelaItens, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnEmitirContratoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmitirContratoActionPerformed
        
        // TODO add your handling code here:
    }//GEN-LAST:event_btnEmitirContratoActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAprovarManutencao;
    private javax.swing.JButton btnCancelarItem;
    private javax.swing.JButton btnCancelarManutencao;
    private javax.swing.JButton btnEmitirContrato;
    private javax.swing.JButton btnNovoItem;
    private javax.swing.JButton btnNovoManutencao;
    private javax.swing.JButton btnPesquisarManutencao;
    private javax.swing.JButton btnRemoverItem;
    private javax.swing.JButton btnSalvarItem;
    private javax.swing.JButton btnSalvarManutencao;
    private javax.swing.JComboBox comboManutencaoDescricaoProduto;
    private javax.swing.JComboBox comboManutencaoNomeCliente;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel labelManutencaoCodProduto;
    private javax.swing.JLabel labelManutencaoCodigo;
    private javax.swing.JLabel labelManutencaoDataManutencao;
    private javax.swing.JLabel labelManutencaoDataPrevManutencao;
    private javax.swing.JLabel labelManutencaoDescricaoProduto;
    private javax.swing.JLabel labelManutencaoNomeCliente;
    private javax.swing.JLabel labelManutencaoProblemaProduto;
    private javax.swing.JLabel labelManutencaoSerieProduto;
    private javax.swing.JLabel labelManutencaoValorTotal;
    private javax.swing.JPanel painelIncluirProduto;
    private javax.swing.JPanel painelManutencao;
    private javax.swing.JScrollPane scrollTabelaItens;
    private javax.swing.JTable tabelaManutencao;
    private javax.swing.JTable tabelaManutencaoItensManutencao;
    private javax.swing.JTextArea txaManutencaoProblemaProduto;
    private javax.swing.JTextField txtManutencaoCodigoManutencao;
    private javax.swing.JTextField txtManutencaoCodigoProduto;
    private javax.swing.JTextField txtManutencaoDataManutencao;
    private javax.swing.JTextField txtManutencaoDataPrevManutencao;
    private javax.swing.JTextField txtManutencaoSerieProduto;
    private javax.swing.JTextField txtManutencaoValorTotal;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setCodigoManutencao(long codigoManutencao) {
        txtManutencaoCodigoManutencao.setText(Long.toString(codigoManutencao));
    }

    @Override
    public long getCodigoManutencao() {
        return Long.parseLong(txtManutencaoCodigoManutencao.getText());
    }

//    @Override
//    public void setCodigoCliente(long codigoCliente) {
//        txtManutencaoCodigoCliente.setText(Long.toString(codigoCliente));
//    }
//
//    @Override
//    public int getCodigoCliente() {
//        return 1;//Integer.parseInt(txtManutencaoCodigoCliente.getText());
//    }
    @Override
    public void setNomeEmpresaManutencao(String nomeCliente) {
        comboManutencaoNomeCliente.setSelectedItem(nomeCliente);
    }

    @Override
    public String getNomeEmpresaManutencao() {
        return comboManutencaoNomeCliente.getSelectedItem().toString();
    }

    @Override
    public void setListaEmpresaManutencao(List<EmpresaManutencaoModel> listaCliente) {
        comboManutencaoNomeCliente.removeAllItems();
        for (int i = 0; i < listaCliente.size(); i++) // Percorro o Array List com o For aprimorado.  
        {
            this.comboManutencaoNomeCliente.addItem(listaCliente.get(i).getNome()); // Adiciono os dados.  
        }
    }

    @Override
    public void setDataSaidaManutencao(String dataManutencao) {
        txtManutencaoDataManutencao.setText(dataManutencao);
    }

    @Override
    public String getDataSaidaManutencao() {
        return txtManutencaoDataManutencao.getText();
    }

    @Override
    public void setDataPrevDevolucao(String dataPrevDevolucao) {
        txtManutencaoDataPrevManutencao.setText(dataPrevDevolucao);
    }

    @Override
    public String getDataPrevDevolucao() {
        return txtManutencaoDataPrevManutencao.getText();
    }

    @Override
    public void setCodigoItemManutencao(long codigoItemManutencao) {
        txtManutencaoCodigoProduto.setText(Long.toString(codigoItemManutencao));
    }

    @Override
    public long getCodigoItemManutencao() {
        return Long.parseLong(txtManutencaoCodigoProduto.getText());
    }

    @Override
    public void setCodigoProduto(long codigoProduto) {
        this.txtManutencaoCodigoProduto.setText(Long.toString(codigoProduto));
    }

    @Override
    public void setSerieItemManutencao(String serieItemLocacal) {
        txtManutencaoSerieProduto.setText(serieItemLocacal);
    }

    @Override
    public String getSerieItemManutencao() {
        return txtManutencaoSerieProduto.getText();
    }

    @Override
    public void setDescricaoItemManutencao(String descricaoItemManutencao) {
        comboManutencaoDescricaoProduto.setSelectedItem(descricaoItemManutencao);
    }

    @Override
    public String getDescricaoItemManutencao() {
        return comboManutencaoDescricaoProduto.getSelectedItem()==null?"1":comboManutencaoDescricaoProduto.getSelectedItem().toString();
    }

    @Override
    public void setValorTotalManutencao(String valorTotalManutencao) {
        txtManutencaoValorTotal.setText((valorTotalManutencao));
    }

    @Override
    public Double getValorTotalManutencao() {
        return Double.parseDouble(txtManutencaoValorTotal.getText().equals("")?"0":(txtManutencaoValorTotal.getText().contains(".")?txtManutencaoValorTotal.getText().replace(".", "").replace(",", "."):txtManutencaoValorTotal.getText().replace(",",".")));
    }
    
    

    @Override
    public void setListaProduto(List<ProdutoModel> listaProdutos) {
        comboManutencaoDescricaoProduto.removeAllItems();
        for (int i = 0; i < listaProdutos.size(); i++) // Percorro o Array List com o For aprimorado.  
        {
            this.comboManutencaoDescricaoProduto.addItem(listaProdutos.get(i).getDescricao()); // Adiciono os dados.  
        }
    }

    @Override
    public long getCodigoProduto() {
        return Long.parseLong(txtManutencaoCodigoProduto.getText());
    }

    @Override
    public void packAndShow() {
        ConfiguracaoInstancias.getDesktop().getDesktop().add(this);
        txtManutencaoDataManutencao.setEditable(false);
        //txtManutencaoDataPrevManutencao.set(true);
        this.pack();
        this.setVisible(true);
    }
    
    @Override
    public void setMascaraListener(KeyListener listener) {
        this.txtManutencaoDataPrevManutencao.addKeyListener(listener);        
    }
 
    @Override
    public void clearFields() {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void enableTxtCodigoManutencao(boolean arg) {
        txtManutencaoCodigoManutencao.setEnabled(arg);
    }

    @Override
    public void enableTxtCodigoEmpresaManutencao(boolean arg) {
        //txtManutencaoCodigoCliente.setEnabled(arg);
    }

    @Override
    public void enableComboNomeEmpresaManutencao(boolean arg) {
        comboManutencaoNomeCliente.setEnabled(arg);
    }

    @Override
    public void enableTxtDataSaidaMenutencao(boolean arg) {
        txtManutencaoDataManutencao.setEnabled(arg);
    }

    @Override
    public void enableTxtDataPrevDevol(boolean arg) {
        txtManutencaoDataPrevManutencao.setEnabled(arg);
    }

    @Override
    public void enableTxtCodigoProduto(boolean arg) {
        txtManutencaoCodigoProduto.setEnabled(arg);
    }

    @Override
    public void enableTxtSerieProduto(boolean arg) {
        txtManutencaoSerieProduto.setEnabled(arg);
    }

    @Override
    public void enableComboDescricaoItem(boolean arg) {
        comboManutencaoDescricaoProduto.setEnabled(arg);
    }

    @Override
    public void enableBtnCancelarManutencao(boolean arg) {
        btnCancelarManutencao.setEnabled(arg);
    }

    @Override
    public void enableBtnSalvarManutencao(boolean arg) {
        btnSalvarManutencao.setEnabled(arg);
    }

    @Override
    public void enableBtnInserirItem(boolean arg) {
        btnNovoItem.setEnabled(arg);
    }

    @Override
    public void enableBtnNovaManutencao(boolean arg) {
        btnNovoManutencao.setEnabled(arg);
    }

    @Override
    public void enableBtnSalvarItem(boolean arg) {
        btnSalvarItem.setEnabled(arg);
    }

    @Override
    public void enableBtnCancelarItem(boolean arg) {
        btnCancelarItem.setEnabled(arg);
    }

    @Override
    public void enableBtnRemoverItem(boolean arg) {
        btnRemoverItem.setEnabled(arg);
    }
    
    @Override
    public void changeStatusManutencao() {
        btnAprovarManutencao.setBackground(Color.GREEN);
        btnAprovarManutencao.setText("Locação Aprovada");
    }

    public void setManutencaoTableModel(ManutencaoTableModel manutencaoTableModel) {
        this.tabelaManutencao.setModel(manutencaoTableModel);
        
        // Configura as colunas da JTable  
        TableColumnModel columnModel = this.tabelaManutencao.getColumnModel();

        columnModel.getColumn(0).setHeaderValue("Cód.Manut.");
        columnModel.getColumn(0).setPreferredWidth(20);

        columnModel.getColumn(1).setHeaderValue("Nome Emp. Manutenção");
        columnModel.getColumn(1).setPreferredWidth(100);

        columnModel.getColumn(2).setHeaderValue("Data Saída");
        columnModel.getColumn(2).setPreferredWidth(30);

        columnModel.getColumn(3).setHeaderValue("Data Prev. Devol");
        columnModel.getColumn(3).setPreferredWidth(30);

    }
    
    @Override
    public void removeAllitensComboEmpresaManutencao() {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeAllitensComboProduto() {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setItensManutencaoTableModel(ItensManutencaoTableModel itensManutencaoTableModel) {
        this.tabelaManutencaoItensManutencao.setModel(itensManutencaoTableModel);

        // Configura as colunas da JTable  
        TableColumnModel columnModel = this.tabelaManutencaoItensManutencao.getColumnModel();

        columnModel.getColumn(0).setHeaderValue("Cód.");
        columnModel.getColumn(0).setPreferredWidth(20);

        columnModel.getColumn(1).setHeaderValue("Série");
        columnModel.getColumn(1).setPreferredWidth(30);

        columnModel.getColumn(2).setHeaderValue("Descrição");
        columnModel.getColumn(2).setPreferredWidth(100);

        columnModel.getColumn(3).setHeaderValue("Vlr Prod.");
        columnModel.getColumn(3).setPreferredWidth(30);
       
    }

    @Override
    public ItensManutencaoTableModel getitensManutencaoTableModel() {
        return (ItensManutencaoTableModel) this.tabelaManutencaoItensManutencao.getModel();//throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void refreshTableItensManutencao() {
        this.tabelaManutencaoItensManutencao.updateUI();
    }
    
    public void refreshTableManutencao() {
        this.tabelaManutencao.updateUI();
    }
    
    public ManutencaoTableModel getManutencaoTableModel() {
        return (ManutencaoTableModel) this.tabelaManutencao.getModel();//throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setInserirItemManutencaoActionListener(ActionListener listener) {
        this.btnNovoItem.addActionListener(listener);
    }

    @Override
    public void setInserirManutencaoActionListener(ActionListener listener) {
        this.btnNovoManutencao.addActionListener(listener);
    }

    @Override
    public void setRemoverItemManutencaoActionListener(ActionListener listener) {
        this.btnRemoverItem.addActionListener(listener);
    }

    @Override
    public void setAlterarActionListener(ActionListener listener) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setCancelarManutencaoActionListener(ActionListener listener) {
        this.btnCancelarManutencao.addActionListener(listener);
    }

    @Override
    public void setCancelarItemManutencaoActionListener(ActionListener listener) {
        this.btnCancelarItem.addActionListener(listener);
    }

    @Override
    public void setSalvarManutencaoActionListener(ActionListener listener) {
        this.btnSalvarManutencao.addActionListener(listener);
    }

    @Override
    public void setSalvarItemManutencaoActionListener(ActionListener listener) {
        this.btnSalvarItem.addActionListener(listener);
    }

    @Override
    public void setBtnSairActionListener(ActionListener listener) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public void setBuscaAvancadaActionListener(ActionListener listener) {
        this.btnPesquisarManutencao.addActionListener(listener);
    }

    @Override
    public void setValorTotalFocusListener(FocusListener listener) {
        this.txtManutencaoValorTotal.addFocusListener(listener);
    }
    
    @Override
    public void setCamposValorKeyListener(KeyListener listener) {
        
        this.txtManutencaoValorTotal.addKeyListener(listener);
        
    }

    @Override
    public void removeAllitensComboNomeEmpresaManutencao() {
        this.comboManutencaoNomeCliente.removeAllItems();
    }

    @Override
    public void removeAllitensComboDescricaoProduto() {
        this.comboManutencaoDescricaoProduto.removeAllItems();
    }

    @Override
    public void setComboDescricaoProdutoItemStateChanged(ItemListener itemListener) {
        this.comboManutencaoDescricaoProduto.addItemListener(itemListener);
    }

    @Override
    public void clearFieldsPainelManutencao() {
        Component[] componentesPainel;
        componentesPainel = painelManutencao.getComponents();
        for (int j = 0; j < componentesPainel.length; j++) {
            if (componentesPainel[j] instanceof JTextField) {
                JTextField field = (JTextField) componentesPainel[j];
                field.setText("");
            }
        }
    }

    @Override
    public void clearFieldsPainelIncluirProdutos() {
        Component[] componentesPainel;
        componentesPainel = painelIncluirProduto.getComponents();
        for (int j = 0; j < componentesPainel.length; j++) {
            if (componentesPainel[j] instanceof JTextField) {
                JTextField field = (JTextField) componentesPainel[j];
                field.setText("");
            }
        }
    }

    @Override
    public void setComboEmpresaManutencaoFocus() {
        this.comboManutencaoNomeCliente.requestFocus();
    }

    @Override
    public void setComboProdutosFocus() {
        this.comboManutencaoDescricaoProduto.requestFocus();
    }

    @Override
    public int linhaSelecionadaTableItens() {
        return this.tabelaManutencaoItensManutencao.getSelectedRow();
    }
    
    public int linhaSelecionadaTableManutencao() {
        return this.tabelaManutencao.getSelectedRow();
    }
    
    @Override
    public void setTableItensManutencaoMouseListener(MouseListener listener) {
        this.tabelaManutencaoItensManutencao.addMouseListener(listener);
    }
    
    public void setTableManutencaoMouseListener(MouseListener listener) {
        this.tabelaManutencao.addMouseListener(listener);
    }

    @Override
    public void clearTableItensManutencao() {
        //tabelaManutencaoItensManutencao.updateUI();
    }

    @Override
    public void setDocument(Document doc) {
        //txtManutencaoValorItem.setDocument(doc);
        //txtManutencaoValorProduto.setDocument(doc);
        txtManutencaoValorTotal.setDocument(doc);
    }


    @Override
    public void focusGained(FocusEvent e) {
        if(e.getSource()==txtManutencaoCodigoManutencao) {
            txtManutencaoCodigoManutencao.selectAll();
        } else if(e.getSource()==txtManutencaoCodigoProduto) {
            txtManutencaoCodigoProduto.selectAll();     
        } else if(e.getSource()==txtManutencaoDataPrevManutencao) {
            txtManutencaoDataPrevManutencao.selectAll();
        }        
    }

    @Override
    public void focusLost(FocusEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setComboEmpresaManutencaosFocus() {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setProblemaItemManutencao(String problemaItemManutencao) {
        this.txaManutencaoProblemaProduto.setText(problemaItemManutencao);
    }

    @Override
    public String getProblemaItemManutencao() {
        return txaManutencaoProblemaProduto.getText();
    }
    
    
   
}
